package com.zp.service;

import lombok.SneakyThrows;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author zp
 * @description 续约调度服务
 * @created 2021/11/25 10:59
 */

public class RenewalService {
    private final ScheduledExecutorService scheduledService = Executors.newSingleThreadScheduledExecutor();
    private static final Log log = LogFactory.getLog(RenewalService.class);

    @Autowired
    private RegisterService registerService;

    public void start(){
        log.info("续约服务正式开启...");
        scheduledService.scheduleAtFixedRate(new RenewalThread(),3,3, TimeUnit.SECONDS);
    }

    class RenewalThread implements Runnable{

        @Override
        public void run() {
            log.info("心跳续约发送....");
            try {
                registerService.renewal();
            } catch (Exception e) {
                log.error(e);
            }
        }
    }
}
